package net.runman.web.front;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import net.runman.core.service.ILinksService;
import net.runman.core.service.IUsersService;

@Controller
public class IndexController {
	private static final Logger logger = LogManager.getLogger(IndexController.class);

	@Autowired private IUsersService usersService;

	@Autowired private ILinksService linksService;
	// 邮件发送参考
	// spring boot mail-> http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-email
	// spring mail-> http://docs.spring.io/spring/docs/4.2.0.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/#mail
	@Autowired private JavaMailSender sender;

	@GetMapping(value = { "/", "/index.html" })
	public String index(Model model) {

//		TUsers users = new TUsers();
//		users.setUserEmail("596392912@qq.com");
//		users.setUserNicename("Dreamlu");
//		users.setUserPass(DigestUtils.md5Hex("123456"));
//		users.setUserRegistered(new Date());
//
//		int updateCount = usersService.addUsers(users);
//		// 发布用户保存的事件
//		SpringUtils.getContext().publishEvent(new UserSaveEvent(users));
//
//		logger.error(Thread.currentThread().getName() + "\tuser id:{} updateCount:{}", users.getId(), updateCount);
//
//		// 邮件发送
//		SimpleMailMessage templateMessage = new SimpleMailMessage();
//		templateMessage.setTo("596392912@qq.com");
//		templateMessage.setSubject("测试邮件哦");
//		templateMessage.setText("hello");
//		templateMessage.setFrom("dreamlu<dreamlu@139.com>");
////		sender.send(templateMessage);
//		
//		TLinks links = new TLinks();
//		links.setLinkName("hello");
//		links.setLinkUrl("http:www.baidu.cn");
//		links.setLinkImage("image");
//		links.setLinkVisible("y");
//		links.setLinkOwner(1l);
//		links.setLinkTarget("target");
//		links.setLinkUpdated(new Date());
//		links.setLinkDescription("测试");
//		linksService.saveLinks(links);
//
//		model.addAttribute("user", usersService.getUsers(users.getId()));
		return "index";
	}

	/**
	 * 文章页
	 * 2012/05/16/facebook-buys-lightbox-an-android-photo-sharing-app/
	 * @return
	 */
	@GetMapping("archive")
	public String archive() {
		return "archive";
	}

}
